package com.ruoyi.biz.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.ruoyi.biz.domain.BizCourse;
import com.ruoyi.biz.domain.BizSubject;
import com.ruoyi.biz.mapper.BizCourseMapper;
import com.ruoyi.biz.mapper.BizSubjectMapper;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.biz.mapper.BizCourseDetailMapper;
import com.ruoyi.biz.domain.BizCourseDetail;
import com.ruoyi.biz.service.IBizCourseDetailService;
import com.ruoyi.common.core.text.Convert;

/**
 * 课程列Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-08-10
 */
@Service
public class BizCourseDetailServiceImpl implements IBizCourseDetailService 
{
    @Autowired
    private BizCourseDetailMapper bizCourseDetailMapper;

    @Autowired
    private BizSubjectMapper bizSubjectMapper;
    @Autowired
    BizCourseMapper courseMapper;

    /**
     * 查询课程列
     * 
     * @param id 课程列ID
     * @return 课程列
     */
    @Override
    public BizCourseDetail selectBizCourseDetailById(Long id)
    {
        return bizCourseDetailMapper.selectBizCourseDetailById(id);
    }

    /**
     * 查询课程列列表
     * 
     * @param bizCourseDetail 课程列
     * @return 课程列
     */
    @Override
    public List<BizCourseDetail> selectBizCourseDetailList(BizCourseDetail bizCourseDetail)
    {
        return bizCourseDetailMapper.selectBizCourseDetailList(bizCourseDetail);
    }

    /**
     * 新增课程列
     * 
     * @param bizCourseDetail 课程列
     * @return 结果
     */
    @Override
    public int insertBizCourseDetail(BizCourseDetail bizCourseDetail)
    {
        bizCourseDetail.setCreateTime(DateUtils.getNowDate());
        return bizCourseDetailMapper.insertBizCourseDetail(bizCourseDetail);
    }

    /**
     * 修改课程列
     * 
     * @param bizCourseDetail 课程列
     * @return 结果
     */
    @Override
    public int updateBizCourseDetail(BizCourseDetail bizCourseDetail)
    {
        bizCourseDetail.setUpdateTime(DateUtils.getNowDate());
        return bizCourseDetailMapper.updateBizCourseDetail(bizCourseDetail);
    }

    /**
     * 删除课程列对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteBizCourseDetailByIds(String ids)
    {
        return bizCourseDetailMapper.deleteBizCourseDetailByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除课程列信息
     * 
     * @param id 课程列ID
     * @return 结果
     */
    @Override
    public int deleteBizCourseDetailById(Long id)
    {
        return bizCourseDetailMapper.deleteBizCourseDetailById(id);
    }

    @Override
    public List<Ztree> selectCourseTree() {
        List<BizSubject> bizSubjectList = bizSubjectMapper.selectBizSubjectList(new BizSubject());
        List<Ztree>      ztrees         = new ArrayList<Ztree>();
        for (BizSubject bizSubject : bizSubjectList) {
            Ztree ztree = new Ztree();
            ztree.setId(bizSubject.getId());
            ztree.setpId(bizSubject.getParentId());
            ztree.setName(bizSubject.getSubjectName());
            ztree.setTitle(bizSubject.getSubjectName());
            ztrees.add(ztree);
        }

        List<BizCourse> bizCourses = courseMapper.selectBizCourseList(new BizCourse());
        for (BizCourse c : bizCourses) {
            Ztree ztree = new Ztree();
            ztree.setId(c.getId()-10000); // 为了解决id与subjectId 冲突导致树形菜单出错,使用负号Id,前端确定值时再转回正的
            ztree.setpId(c.getSubjectId());
            ztree.setName(c.getCourseName());
            ztree.setTitle(c.getCourseName());
            ztrees.add(ztree);
        }
        return ztrees;
    }

    @Override
    public List<BizCourseDetail> selectBizCourseDetailListWihtUserInfo(Map param) {
        return bizCourseDetailMapper.selectBizCourseDetailListWihtUserInfo(param);
    }
}
